AppleScript Support in CoolTerm 1.4.7
============================================================================
Version 1.4.7 of CoolTerm includes the following AppleScript Commands:

- WindowCount
- WindowID
- WindowName
- IndexOfWindowID
- NewWindow
- LoadSetting
- Quit
- CloseWindow
- Connect
- Disconnect
- IsConnected
- Write
- WriteLine
- WriteHex
- BytesLeftToSend
- Poll
- Read
- ReadAll
- ReadHex
- ReadAllHex
- BytesAvailable
- LookAhead
- SendBreak
- ResetPort
- FlushPort
- ClearBuffer
- LastErrorCode
- SetDTR
- GetDTR
- SetRTS
- GetRTS
- GetCTS
- GetDSR
- GetDCD
- GetRI
- SendTextFile
- CaptureStart
- CapturePause
- CaptureResume
- CaptureStop

AppleScript for CoolTerm supports multiple terminal windows, i.e. commands
that interact with terminal windows need to be addressed to the intended
window by passing the ID of the window as the first command argument.
The syntax, arguments, and return parameters for each command are documented
below.

----------------------------------------------------------------------------
WindowCount as Integer
----------------------------------------------------------------------------
Returns the number of terminal windows.

E.g.:	set n to WindowCount


----------------------------------------------------------------------------
WindowID(Index as integer) as integer
----------------------------------------------------------------------------
Returns the ID of the window with the specified index.

E.g.:	# Display the IDs of all terminal windows
	repeat with i from 0 to n - 1
		display alert (WindowID (i))
	end repeat

E.g.:	# Get the ID of the first terminal Window
	Set WinID to WindowID (0)


----------------------------------------------------------------------------
WindowName(Index as integer) as string
----------------------------------------------------------------------------
Returns the name of the window with the specified index.

E.g.:	# Display the names of all terminal windows
	repeat with i from 0 to n - 1
		display alert (WindowName (i))
	end repeat


----------------------------------------------------------------------------
IndexOfWindowID(ID as integer) as integer
----------------------------------------------------------------------------
Returns the index of the window with the specified ID

E.g.:	i = IndexOfWindow (WinID)


----------------------------------------------------------------------------
NewWindow as integer
----------------------------------------------------------------------------
Opens a new window and returns the ID if it was successful and -1 if
otherwise.

E.g.:	set WinID to NewWindow


----------------------------------------------------------------------------
LoadSetting(FilePath as String) as Integer
----------------------------------------------------------------------------
Loads the connection settings file with the specified path. Just the file
name can be passed if the settings file resides the same folder as the
CoolTerm application. Otherwise, a full path must be passed to LoadSetting.
Returns the ID of the window (an integer which is >= 0) if the connection
settings file was loaded successfully and -1 if loading was not successful.

E.g.:	set WinID to LoadSetting ("Macintosh HD:MySettings.stc")
 	if WinID >= 0 then
		display alert "The settings have been loaded successfully."
	else
		display alert "The settings could not be loaded."
	end if


----------------------------------------------------------------------------
CloseWindow(ID as integer)
----------------------------------------------------------------------------
Closes the terminal window with the specified ID

E.g.:	CloseWindow (WinID)


----------------------------------------------------------------------------
Quit
----------------------------------------------------------------------------
Quits CoolTerm.

E.g.:	Quit


----------------------------------------------------------------------------
Connect(ID as integer) as Boolean
----------------------------------------------------------------------------
Opens the serial port associated with the terminal window with the specified
name.
Returns TRUE if the port was successfully opened.

E.g.:	if Connect (WinID) then
		display alert "The port is open."
	else
		display alert "The port could not be opened."
	end if


----------------------------------------------------------------------------
Disconnect(ID as integer)
----------------------------------------------------------------------------
Closes the serial port associated with the terminal window with the
specified name.

E.g.:	Disconnect (ID)


----------------------------------------------------------------------------
IsConnected(ID as integer) as Boolean
----------------------------------------------------------------------------
Checks the connection status of the serial port.
Returns TRUE if the port is connected (i.e. open), returns FALSE if the port
is not connected.

E.g.:	if IsConnected (WinID) then
		display alert "The port is open."
	else
		display alert "The port is not open."
	end if


----------------------------------------------------------------------------
Write(ID as integer, Data as String)
----------------------------------------------------------------------------
Writes data to the serial port associated with the terminal window with the
specified name.

E.g.:	Write {WinID, "Hello CoolTerm"}


----------------------------------------------------------------------------
WriteLine(ID as integer, Data as String)
----------------------------------------------------------------------------
Writes data terminated by the "Enter Key Emulation" character specified in
the connection settings to the serial port associated with the terminal
window with the specified name.

E.g.:	Write {WinID, "Writing just one line."}


----------------------------------------------------------------------------
WriteHex(ID as integer, HexData as String)
----------------------------------------------------------------------------
Writes hex data to the serial port associated with the terminal window with
the specified name.

E.g.:	WriteHex {WinID, "48 65 6C 6C 6F 20 43 6F 6F 6C 54 65 72 6D"}


----------------------------------------------------------------------------
BytesLeftToSend(ID as integer) as integer
----------------------------------------------------------------------------
Returns the number of bytes that have not yet left the transmit buffer after
starting a transmission with Write, WriteLine, or SendTextFile.

E.g.:	set b to BytesLeftToSend (WinID)


----------------------------------------------------------------------------
Poll(ID as integer)
----------------------------------------------------------------------------
Polls the serial port associated with the terminal window with the specified
name and causes all data currently available in the serial port receive
buffer to be transferred to CoolTerm's receive buffer. It is recommended to
call this method before calling Read, ReadAll, LookAhead, and BytesAvailable.

E.g.:	Poll (WinID)


----------------------------------------------------------------------------
Read(ID as integer, NumChars as Integer) as String
----------------------------------------------------------------------------
Reads and removes the specified number of characters from the receive buffer
of the terminal window with the specified name.

E.g.:	local txt
	set txt to Read {WinID, 5}


----------------------------------------------------------------------------
ReadAll(ID as integer) as String
----------------------------------------------------------------------------
Reads and removes all characters from the receive buffer of the terminal
window with the specified name.

E.g.:	local txt
	set txt to ReadAll (WinID)


----------------------------------------------------------------------------
ReadHex(ID as integer, NumChars as Integer) as String
----------------------------------------------------------------------------
Reads and removes the specified number of characters in Hex format from the
receive buffer of the terminal window with the specified name.

E.g.:	local txtHex
	set txtHex to ReadHex {WinID, 5}


----------------------------------------------------------------------------
ReadAllHex(ID as integer) as String
----------------------------------------------------------------------------
Reads and removes all characters in Hex format from the receive buffer of the
terminal window with the specified name.

E.g.:	local txtHex
	set txtHex to ReadAllHex (WinID)


----------------------------------------------------------------------------
BytesAvailable(ID as integer) as Integer
----------------------------------------------------------------------------
Returns the number of characters currently available in the receive buffer
of the terminal window with the specified name.

E.g.:	local i
	set i to BytesAvailable (WinID)


----------------------------------------------------------------------------
LookAhead(ID as integer) as String
----------------------------------------------------------------------------
Returns the contents of the receive buffer of the terminal window with the
specified name without removing any data.

E.g.:	local txt
	set txt to LookAhead (WinID)


----------------------------------------------------------------------------
SendBreak(ID as integer)
----------------------------------------------------------------------------
Sends the break signal from the serial port in the specified window.

E.g.:	Break(WinID)


----------------------------------------------------------------------------
ResetPort(ID as integer)
----------------------------------------------------------------------------
Resets the serial port in the specified window.

E.g.:	ResetPort(WinID)


----------------------------------------------------------------------------
FlushPort(ID as integer)
----------------------------------------------------------------------------
Flushes the serial port in the specified window.

E.g.:	FlushPort(WinID)


----------------------------------------------------------------------------
ClearBuffer(ID as integer)
----------------------------------------------------------------------------
Clears receive buffer of the terminal window with the specified name.

E.g.:	ClearBuffer (WinID)


----------------------------------------------------------------------------
LastErrorCode(ID as integer) as integer
----------------------------------------------------------------------------
Returns the code of the last serial port error that occurred in the
specified window.

E.g.:	local e
	set e to LastErrorCode(WinID)


----------------------------------------------------------------------------
SetDTR(ID as integer, value as boolean)
----------------------------------------------------------------------------
Sets the DTR status signal to the specified value.

E.g.:	SetDTR(WinID, true)


----------------------------------------------------------------------------
GetDTR(ID as integer) as boolean
----------------------------------------------------------------------------
Reads the value of the DTR status signal in the specified window.

E.g.:	local v
	set v to GetDTR(WinID)


----------------------------------------------------------------------------
SetRTS(ID as integer, value as boolean)
----------------------------------------------------------------------------
Sets the RTS status signal to the specified value.

E.g.:	SetRTS(WinID, true)


----------------------------------------------------------------------------
GetRTS(ID as integer) as boolean
----------------------------------------------------------------------------
Reads the value of the RTS status signal in the specified window.

E.g.:	local v
	set v to GetRTS(WinID)


----------------------------------------------------------------------------
GetCTS(ID as integer) as boolean
----------------------------------------------------------------------------
Reads the value of the CTS status signal in the specified window.

E.g.:	local v
	set v to GetCTS(WinID)


----------------------------------------------------------------------------
GetDST(ID as integer) as boolean
----------------------------------------------------------------------------
Reads the value of the DST status signal in the specified window.

E.g.:	local v
	set v to GetDST(WinID)


----------------------------------------------------------------------------
GetDCD(ID as integer) as boolean
----------------------------------------------------------------------------
Reads the value of the DCD status signal in the specified window.

E.g.:	local v
	set v to GetDCD(WinID)


----------------------------------------------------------------------------
GetRI(ID as integer) as boolean
----------------------------------------------------------------------------
Reads the value of the RI status signal in the specified window.

E.g.:	local v
	set v to GetRI(WinID)


----------------------------------------------------------------------------
SendTextFile(ID as integer, FilePath as string) as boolean
----------------------------------------------------------------------------
Sends the specified text file via the serial port in the specified window.
Returns false if the file could not be loaded.

E.g.:	if SendTextFile(WinID, "Macintosh HD:MyTextFile.txt") then
		display alert "Success"
	else
		display alert "Failed"
	end if


----------------------------------------------------------------------------
CaptureStart(ID as integer, FilePath as string) as boolean
----------------------------------------------------------------------------
Starts data capture into the specified text file. Returns false if it was
not possible to create the file in the specified location.

E.g.:	if CaptureStart(WinID, "Macintosh HD:MyCaptureFile.txt") then
		display alert "Success"
	else
		display alert "Failed"
	end if


----------------------------------------------------------------------------
CapturePause(ID as integer)
----------------------------------------------------------------------------
Pauses the current capture.

E.g.:	CapturePause(WinID)


----------------------------------------------------------------------------
CaptureResume(ID as integer)
----------------------------------------------------------------------------
Resumes the current capture.

E.g.:	CaptureResume(WinID)


----------------------------------------------------------------------------
CaptureStop(ID as integer)
----------------------------------------------------------------------------
Stops the current capture and closes the capture file.

E.g.:	CaptureStop(WinID)